package com.gitee.springboot.firstlesson.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * @author guoxh
 * @date 2019-08-06 16:36
 * @desc
 */
@Configuration
@EnableWebSocketMessageBroker //启用STOMP协议来传输基于代理(message broker)的消息
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    //注册STOMP协议的节点(endpoint),并映射到指定的url
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //注册一个STOMP的endpoint,并指定使用SocketJS协议
        registry.addEndpoint("/endpointWisely").withSockJS();
    }
    //配置消息代理 Message Broker
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        //广播式 应配置一个/topic消息代理
        registry.enableSimpleBroker("/topic");
    }
}
